<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<title>prencar: D:/Workspace/Arduino/prencar/LineFollow.cpp Source File</title>

<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
  $(document).ready(initResizable);
</script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
  $(document).ready(function() { searchBox.OnSelectItem(0); });
</script>

</head>
<body>
<div id="top"><!-- do not remove this div! -->


<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  
  <td id="projectlogo"><img alt="Logo" src="prencar.png"/></td>
  
  
  <td style="padding-left: 0.5em;">
   <div id="projectname">prencar
   &#160;<span id="projectnumber">1</span>
   </div>
   
  </td>
  
  
  
 </tr>
 </tbody>
</table>
</div>

<!-- Generated by Doxygen 1.8.0 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="pages.html"><span>Related&#160;Pages</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
      <li>
        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <img id="MSearchSelect" src="search/mag_sel.png"
               onmouseover="return searchBox.OnSearchSelectShow()"
               onmouseout="return searchBox.OnSearchSelectHide()"
               alt=""/>
          <input type="text" id="MSearchField" value="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
          </span>
        </div>
      </li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="files.html"><span>File&#160;List</span></a></li>
      <li><a href="globals.html"><span>File&#160;Members</span></a></li>
    </ul>
  </div>
</div>
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
  initNavTree('_line_follow_8cpp.html','');
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark">&#160;</span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark">&#160;</span>Classes</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark">&#160;</span>Files</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark">&#160;</span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark">&#160;</span>Variables</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark">&#160;</span>Enumerations</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(6)"><span class="SelectionMark">&#160;</span>Enumerator</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(7)"><span class="SelectionMark">&#160;</span>Defines</a></div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div class="header">
  <div class="headertitle">
<div class="title">D:/Workspace/Arduino/prencar/LineFollow.cpp</div>  </div>
</div><!--header-->
<div class="contents">
<a href="_line_follow_8cpp.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="preprocessor">#include &quot;Arduino.h&quot;</span>
<a name="l00002"></a>00002 <span class="preprocessor">#include &quot;<a class="code" href="_line_follow_8h.html">LineFollow.h</a>&quot;</span>
<a name="l00003"></a>00003 <span class="preprocessor">#include &quot;<a class="code" href="_move_8h.html">Move.h</a>&quot;</span>
<a name="l00004"></a>00004 <span class="preprocessor">#include &quot;<a class="code" href="_configuration_8h.html">Configuration.h</a>&quot;</span>
<a name="l00005"></a>00005 
<a name="l00009"></a><a class="code" href="class_line_follow.html#ace2e49549627ad0682ed71e0be714086">00009</a> <a class="code" href="class_line_follow.html#ace2e49549627ad0682ed71e0be714086">LineFollow::LineFollow</a>()
<a name="l00010"></a>00010 {
<a name="l00011"></a>00011 
<a name="l00012"></a>00012 }
<a name="l00013"></a>00013 
<a name="l00019"></a><a class="code" href="class_line_follow.html#afac0ad1ff185b7e5f9b47428cb2e5e48">00019</a> <span class="keywordtype">void</span> <a class="code" href="class_line_follow.html#afac0ad1ff185b7e5f9b47428cb2e5e48">LineFollow::begin</a>(){
<a name="l00020"></a>00020   <a class="code" href="class_line_follow.html#a8c494126e578f00240532b866b051718" title="The reference to the serial communication class.">_com</a> = <a class="code" href="class_communication.html#ad7b13fccf78bfce83efc9bb06c64facd">Communication::getInstance</a>();
<a name="l00021"></a>00021   <a class="code" href="class_line_follow.html#ac6fe17d43571248ea2e74fade7ceb5bd" title="The reference to the move class to control the motors.">_move</a> = <a class="code" href="class_move.html#a5b53cfa443fe4fe0f1b96f9b3afc4850">Move::getInstance</a>();
<a name="l00022"></a>00022   <a class="code" href="class_line_follow.html#a0112816d723edd82daf2dabbf1ff074f" title="The reference to the configuration class.">_conf</a> = <a class="code" href="class_configuration.html#ae327d26e81014cf46b25802478fe9b8e">Configuration::getInstance</a>();
<a name="l00023"></a>00023 
<a name="l00024"></a>00024   pinMode(<a class="code" href="class_line_follow.html#a0112816d723edd82daf2dabbf1ff074f" title="The reference to the configuration class.">_conf</a>-&gt;<a class="code" href="class_configuration.html#a09d83c2f3c4485fd864bf998e62788d7">lineFollowLeftSensorPin</a>, INPUT);
<a name="l00025"></a>00025   pinMode(<a class="code" href="class_line_follow.html#a0112816d723edd82daf2dabbf1ff074f" title="The reference to the configuration class.">_conf</a>-&gt;<a class="code" href="class_configuration.html#a254b7ac19c994603776d47645235a132">lineFollowRightSensorPin</a>, INPUT);
<a name="l00026"></a>00026   pinMode(<a class="code" href="class_line_follow.html#a0112816d723edd82daf2dabbf1ff074f" title="The reference to the configuration class.">_conf</a>-&gt;<a class="code" href="class_configuration.html#a683b496d15eca4addb13325d9707abcf">lineFollowLeftFrontSensorPin</a>, INPUT);
<a name="l00027"></a>00027   pinMode(<a class="code" href="class_line_follow.html#a0112816d723edd82daf2dabbf1ff074f" title="The reference to the configuration class.">_conf</a>-&gt;<a class="code" href="class_configuration.html#ab8d7a8d9f62cfafe082cc32915ef4bfa">lineFollowRightFrontSensorPin</a>, INPUT);
<a name="l00028"></a>00028 
<a name="l00029"></a>00029   <span class="comment">//make sure, the pull up resistors are off</span>
<a name="l00030"></a>00030   digitalWrite(<a class="code" href="class_line_follow.html#a0112816d723edd82daf2dabbf1ff074f" title="The reference to the configuration class.">_conf</a>-&gt;<a class="code" href="class_configuration.html#a09d83c2f3c4485fd864bf998e62788d7">lineFollowLeftSensorPin</a>, LOW);
<a name="l00031"></a>00031   digitalWrite(<a class="code" href="class_line_follow.html#a0112816d723edd82daf2dabbf1ff074f" title="The reference to the configuration class.">_conf</a>-&gt;<a class="code" href="class_configuration.html#a254b7ac19c994603776d47645235a132">lineFollowRightSensorPin</a>, LOW);
<a name="l00032"></a>00032   digitalWrite(<a class="code" href="class_line_follow.html#a0112816d723edd82daf2dabbf1ff074f" title="The reference to the configuration class.">_conf</a>-&gt;<a class="code" href="class_configuration.html#a683b496d15eca4addb13325d9707abcf">lineFollowLeftFrontSensorPin</a>, LOW);
<a name="l00033"></a>00033   digitalWrite(<a class="code" href="class_line_follow.html#a0112816d723edd82daf2dabbf1ff074f" title="The reference to the configuration class.">_conf</a>-&gt;<a class="code" href="class_configuration.html#ab8d7a8d9f62cfafe082cc32915ef4bfa">lineFollowRightFrontSensorPin</a>, LOW);
<a name="l00034"></a>00034 
<a name="l00035"></a>00035   <a class="code" href="class_line_follow.html#accb339a7a953d66032b9329a2b3a1b4d" title="Is set to true, if the left curve line is reached.">hasReachedCurve</a> = <span class="keyword">false</span>;
<a name="l00036"></a>00036 }
<a name="l00037"></a>00037 
<a name="l00041"></a><a class="code" href="class_line_follow.html#a5f3e76e795bacff24be60b7f65d84d94">00041</a> <span class="keywordtype">void</span> <a class="code" href="class_line_follow.html#a5f3e76e795bacff24be60b7f65d84d94">LineFollow::startIt</a>(){
<a name="l00042"></a>00042   <a class="code" href="class_line_follow.html#accb339a7a953d66032b9329a2b3a1b4d" title="Is set to true, if the left curve line is reached.">hasReachedCurve</a> = <span class="keyword">false</span>;
<a name="l00043"></a>00043   
<a name="l00044"></a>00044   <a class="code" href="class_line_follow.html#a44ff5bd13460ce3d6737319c6d0023f0">_deltasensor</a> = 0;
<a name="l00045"></a>00045   <a class="code" href="class_line_follow.html#ae28a165a4eaf1ab88fe0cab11e325ba7">_sensoralt</a> = 20;
<a name="l00046"></a>00046   <a class="code" href="class_line_follow.html#aaef3837f6fd0ea4d69458dbe7a5ed54d">_deltaPWM</a> = 0;
<a name="l00047"></a>00047 
<a name="l00048"></a>00048   <a class="code" href="class_line_follow.html#ac6fe17d43571248ea2e74fade7ceb5bd" title="The reference to the move class to control the motors.">_move</a>-&gt;<a class="code" href="class_move.html#a9c5dc5c3a98abece0c2f40085c3601be">controlMotors</a>(<a class="code" href="_move_8h.html#a4d576498f070661245f38f5f34d34f02a726a0af5164861adac8c015a742dcf21" title="The motor rotates forward.">forward</a>, <a class="code" href="class_line_follow.html#a0112816d723edd82daf2dabbf1ff074f" title="The reference to the configuration class.">_conf</a>-&gt;<a class="code" href="class_configuration.html#a24e118088874b8f9d56bcaf245f1461d" title="The initial speed of the left motor when the parcours starts (0-255).">lineFollowInitialSpeedLeft</a>, <a class="code" href="_move_8h.html#a4d576498f070661245f38f5f34d34f02a726a0af5164861adac8c015a742dcf21" title="The motor rotates forward.">forward</a>, <a class="code" href="class_line_follow.html#a0112816d723edd82daf2dabbf1ff074f" title="The reference to the configuration class.">_conf</a>-&gt;<a class="code" href="class_configuration.html#aabc113e529eb659768ca98f15d3952a3" title="The initial speed of the left motor when the parcours starts (0-255).">lineFollowInitialSpeedRight</a>);
<a name="l00049"></a>00049 }
<a name="l00050"></a>00050 
<a name="l00063"></a><a class="code" href="class_line_follow.html#a93ff35747f2ae3bb26998f07243afc3c">00063</a> <span class="keywordtype">void</span> <a class="code" href="class_line_follow.html#a93ff35747f2ae3bb26998f07243afc3c">LineFollow::doJob</a>(){
<a name="l00064"></a>00064   <span class="keywordflow">if</span>(<a class="code" href="class_line_follow.html#a0112816d723edd82daf2dabbf1ff074f" title="The reference to the configuration class.">_conf</a>-&gt;<a class="code" href="class_configuration.html#aa799e7ed6a4722085506a31c051bf103" title="Interval in milliseconds in which the line follow job shall be executed.">lineFollowInterval</a> == 0 || millis() &gt; <a class="code" href="class_line_follow.html#a9c31b9a1c2d0627dcbfdb2af0bf7778e" title="Holds the timestamp of the time when the last line follow check was done.">_timeLastLineFollowCheck</a> + <a class="code" href="class_line_follow.html#a0112816d723edd82daf2dabbf1ff074f" title="The reference to the configuration class.">_conf</a>-&gt;<a class="code" href="class_configuration.html#aa799e7ed6a4722085506a31c051bf103" title="Interval in milliseconds in which the line follow job shall be executed.">lineFollowInterval</a>){
<a name="l00065"></a>00065     <a class="code" href="class_line_follow.html#a9c31b9a1c2d0627dcbfdb2af0bf7778e" title="Holds the timestamp of the time when the last line follow check was done.">_timeLastLineFollowCheck</a> = millis();
<a name="l00066"></a>00066 
<a name="l00067"></a>00067     <span class="keywordtype">int</span> sensorValues[2];
<a name="l00068"></a>00068     <a class="code" href="class_line_follow.html#a1e3bb3e01044c86e7ad87c632bac6634">readFrontLineSensors</a>(sensorValues);
<a name="l00069"></a>00069 
<a name="l00070"></a>00070     <span class="comment">//check if a 90° curve is needed</span>
<a name="l00071"></a>00071     <span class="keywordflow">if</span>(sensorValues[0] &lt; <a class="code" href="class_line_follow.html#a0112816d723edd82daf2dabbf1ff074f" title="The reference to the configuration class.">_conf</a>-&gt;<a class="code" href="class_configuration.html#a6c0d6f8b78ea6b6e167c80bce9447906" title="Threshold value from black to white.">lineFollowWhiteThreshold</a>){
<a name="l00072"></a>00072       <a class="code" href="class_line_follow.html#a8c494126e578f00240532b866b051718" title="The reference to the serial communication class.">_com</a>-&gt;<a class="code" href="class_communication.html#a8679b3cb7ceef5527faa24454ce0f18a">send</a>(55, sensorValues[0]);
<a name="l00073"></a>00073       <a class="code" href="class_line_follow.html#ac6fe17d43571248ea2e74fade7ceb5bd" title="The reference to the move class to control the motors.">_move</a>-&gt;<a class="code" href="class_move.html#a237261f2dd8fc115129f0ba998f13183">performFastStop</a>();
<a name="l00074"></a>00074       <a class="code" href="class_line_follow.html#accb339a7a953d66032b9329a2b3a1b4d" title="Is set to true, if the left curve line is reached.">hasReachedCurve</a> = <span class="keyword">true</span>;
<a name="l00075"></a>00075       <span class="keywordflow">return</span>;
<a name="l00076"></a>00076     }
<a name="l00077"></a>00077 
<a name="l00078"></a>00078     <span class="comment">//Do the line following</span>
<a name="l00079"></a>00079     <a class="code" href="class_line_follow.html#af85fe355ee0699cabc3c817d10aa8b9d">readLineSensors</a>(sensorValues);
<a name="l00080"></a>00080     <a class="code" href="class_line_follow.html#a44ff5bd13460ce3d6737319c6d0023f0">_deltasensor</a> = sensorValues[0]-sensorValues[1];
<a name="l00081"></a>00081     <a class="code" href="class_line_follow.html#a8c494126e578f00240532b866b051718" title="The reference to the serial communication class.">_com</a>-&gt;<a class="code" href="class_communication.html#a8679b3cb7ceef5527faa24454ce0f18a">send</a>(3, <a class="code" href="class_line_follow.html#a44ff5bd13460ce3d6737319c6d0023f0">_deltasensor</a>);
<a name="l00082"></a>00082     <a class="code" href="class_line_follow.html#aaef3837f6fd0ea4d69458dbe7a5ed54d">_deltaPWM</a> = (int) ( ((<span class="keywordtype">float</span>)<a class="code" href="class_line_follow.html#a0112816d723edd82daf2dabbf1ff074f" title="The reference to the configuration class.">_conf</a>-&gt;<a class="code" href="class_configuration.html#aabaf837f8816911a6d0b1e8cd7867cb9">lineFollowKp</a>) * (((float)<a class="code" href="class_line_follow.html#a44ff5bd13460ce3d6737319c6d0023f0">_deltasensor</a>)/100) + ((<span class="keywordtype">float</span>)<a class="code" href="class_line_follow.html#a0112816d723edd82daf2dabbf1ff074f" title="The reference to the configuration class.">_conf</a>-&gt;<a class="code" href="class_configuration.html#aad2572d8c68520c2ef6613d29f38a9cf">lineFollowKd</a>)/100 * (<span class="keywordtype">float</span>)(_deltasensor-<a class="code" href="class_line_follow.html#ae28a165a4eaf1ab88fe0cab11e325ba7">_sensoralt</a>) );
<a name="l00083"></a>00083     <a class="code" href="class_line_follow.html#a8c494126e578f00240532b866b051718" title="The reference to the serial communication class.">_com</a>-&gt;<a class="code" href="class_communication.html#a8679b3cb7ceef5527faa24454ce0f18a">send</a>(4, <a class="code" href="class_line_follow.html#aaef3837f6fd0ea4d69458dbe7a5ed54d">_deltaPWM</a>);
<a name="l00084"></a>00084     <a class="code" href="class_line_follow.html#ae28a165a4eaf1ab88fe0cab11e325ba7">_sensoralt</a> = <a class="code" href="class_line_follow.html#a44ff5bd13460ce3d6737319c6d0023f0">_deltasensor</a>;
<a name="l00085"></a>00085     <a class="code" href="class_line_follow.html#ac6fe17d43571248ea2e74fade7ceb5bd" title="The reference to the move class to control the motors.">_move</a>-&gt;<a class="code" href="class_move.html#a5ba1c7d78d6a067bc3cfa5f9cdca921f">changeMotorSpeedBasedOnInitialSpeed</a>(<a class="code" href="class_line_follow.html#aaef3837f6fd0ea4d69458dbe7a5ed54d">_deltaPWM</a>,(-1)*<a class="code" href="class_line_follow.html#aaef3837f6fd0ea4d69458dbe7a5ed54d">_deltaPWM</a>); 
<a name="l00086"></a>00086   }
<a name="l00087"></a>00087 }
<a name="l00088"></a>00088 
<a name="l00093"></a><a class="code" href="class_line_follow.html#a1e3bb3e01044c86e7ad87c632bac6634">00093</a> <span class="keywordtype">void</span> <a class="code" href="class_line_follow.html#a1e3bb3e01044c86e7ad87c632bac6634">LineFollow::readFrontLineSensors</a>(<span class="keywordtype">int</span>* resultArray){
<a name="l00094"></a>00094 
<a name="l00095"></a>00095   resultArray[0] = analogRead(<a class="code" href="class_line_follow.html#a0112816d723edd82daf2dabbf1ff074f" title="The reference to the configuration class.">_conf</a>-&gt;<a class="code" href="class_configuration.html#a683b496d15eca4addb13325d9707abcf">lineFollowLeftFrontSensorPin</a>);
<a name="l00097"></a>00097   resultArray[1] = analogRead(<a class="code" href="class_line_follow.html#a0112816d723edd82daf2dabbf1ff074f" title="The reference to the configuration class.">_conf</a>-&gt;<a class="code" href="class_configuration.html#ab8d7a8d9f62cfafe082cc32915ef4bfa">lineFollowRightFrontSensorPin</a>);
<a name="l00098"></a>00098 
<a name="l00099"></a>00099   <a class="code" href="class_line_follow.html#a8c494126e578f00240532b866b051718" title="The reference to the serial communication class.">_com</a>-&gt;<a class="code" href="class_communication.html#a8679b3cb7ceef5527faa24454ce0f18a">send</a>(1, resultArray, 2);
<a name="l00100"></a>00100 }
<a name="l00101"></a>00101 
<a name="l00106"></a><a class="code" href="class_line_follow.html#af85fe355ee0699cabc3c817d10aa8b9d">00106</a> <span class="keywordtype">void</span> <a class="code" href="class_line_follow.html#af85fe355ee0699cabc3c817d10aa8b9d">LineFollow::readLineSensors</a>(<span class="keywordtype">int</span>* resultArray){
<a name="l00107"></a>00107 
<a name="l00108"></a>00108   resultArray[0] = analogRead(<a class="code" href="class_line_follow.html#a0112816d723edd82daf2dabbf1ff074f" title="The reference to the configuration class.">_conf</a>-&gt;<a class="code" href="class_configuration.html#a09d83c2f3c4485fd864bf998e62788d7">lineFollowLeftSensorPin</a>);
<a name="l00110"></a>00110   resultArray[1] = analogRead(<a class="code" href="class_line_follow.html#a0112816d723edd82daf2dabbf1ff074f" title="The reference to the configuration class.">_conf</a>-&gt;<a class="code" href="class_configuration.html#a254b7ac19c994603776d47645235a132">lineFollowRightSensorPin</a>);
<a name="l00111"></a>00111 
<a name="l00112"></a>00112   <a class="code" href="class_line_follow.html#a8c494126e578f00240532b866b051718" title="The reference to the serial communication class.">_com</a>-&gt;<a class="code" href="class_communication.html#a8679b3cb7ceef5527faa24454ce0f18a">send</a>(2, resultArray, 2);
<a name="l00113"></a>00113 }
<a name="l00114"></a>00114 
<a name="l00136"></a><a class="code" href="class_line_follow.html#a9db172747e4457a6b01f8d27ed41ac39">00136</a> <span class="keywordtype">void</span> <a class="code" href="class_line_follow.html#a9db172747e4457a6b01f8d27ed41ac39" title="Calibrates the sensors.">LineFollow::calibrateSensors</a>(){
<a name="l00137"></a>00137   <span class="keywordtype">float</span> sensorValue;
<a name="l00138"></a>00138   <a class="code" href="class_line_follow.html#a8c494126e578f00240532b866b051718" title="The reference to the serial communication class.">_com</a>-&gt;<a class="code" href="class_communication.html#a8679b3cb7ceef5527faa24454ce0f18a">send</a>(200);
<a name="l00139"></a>00139   delay(10000);
<a name="l00140"></a>00140   <a class="code" href="class_line_follow.html#a8c494126e578f00240532b866b051718" title="The reference to the serial communication class.">_com</a>-&gt;<a class="code" href="class_communication.html#a8679b3cb7ceef5527faa24454ce0f18a">send</a>(201);
<a name="l00141"></a>00141 
<a name="l00142"></a>00142   <span class="comment">//sensor measurement on black ground</span>
<a name="l00143"></a>00143   <a class="code" href="class_line_follow.html#aeb722614b85d484aafe0714f9d319f3e" title="Holds the minimum value that was measured during the calibration for &quot;black&quot;.">_calibrationSensorBlackMin</a> = 1023;
<a name="l00144"></a>00144   <a class="code" href="class_line_follow.html#aaeea70b897deb0295401aa316189c2ba" title="Holds the maximum value that was measured during the calibration for &quot;black&quot;.">_calibrationSensorBlackMax</a> = 0;
<a name="l00145"></a>00145   <span class="keywordflow">for</span>(byte i = 0; i &lt; 50; i++){
<a name="l00146"></a>00146     sensorValue = analogRead(<a class="code" href="class_line_follow.html#a0112816d723edd82daf2dabbf1ff074f" title="The reference to the configuration class.">_conf</a>-&gt;<a class="code" href="class_configuration.html#a683b496d15eca4addb13325d9707abcf">lineFollowLeftFrontSensorPin</a>);
<a name="l00147"></a>00147     <span class="keywordflow">if</span>(sensorValue &lt; <a class="code" href="class_line_follow.html#aeb722614b85d484aafe0714f9d319f3e" title="Holds the minimum value that was measured during the calibration for &quot;black&quot;.">_calibrationSensorBlackMin</a>){
<a name="l00148"></a>00148       <a class="code" href="class_line_follow.html#aeb722614b85d484aafe0714f9d319f3e" title="Holds the minimum value that was measured during the calibration for &quot;black&quot;.">_calibrationSensorBlackMin</a> = sensorValue;
<a name="l00149"></a>00149     }
<a name="l00150"></a>00150     <span class="keywordflow">if</span>(sensorValue &gt; <a class="code" href="class_line_follow.html#aaeea70b897deb0295401aa316189c2ba" title="Holds the maximum value that was measured during the calibration for &quot;black&quot;.">_calibrationSensorBlackMax</a>){
<a name="l00151"></a>00151       <a class="code" href="class_line_follow.html#aaeea70b897deb0295401aa316189c2ba" title="Holds the maximum value that was measured during the calibration for &quot;black&quot;.">_calibrationSensorBlackMax</a> = sensorValue;
<a name="l00152"></a>00152     }
<a name="l00153"></a>00153     delay(100);
<a name="l00154"></a>00154   }
<a name="l00155"></a>00155 
<a name="l00156"></a>00156   <a class="code" href="class_line_follow.html#a8c494126e578f00240532b866b051718" title="The reference to the serial communication class.">_com</a>-&gt;<a class="code" href="class_communication.html#a8679b3cb7ceef5527faa24454ce0f18a">send</a>(202);
<a name="l00157"></a>00157   delay(10000);
<a name="l00158"></a>00158   <a class="code" href="class_line_follow.html#a8c494126e578f00240532b866b051718" title="The reference to the serial communication class.">_com</a>-&gt;<a class="code" href="class_communication.html#a8679b3cb7ceef5527faa24454ce0f18a">send</a>(201);
<a name="l00159"></a>00159 
<a name="l00160"></a>00160   <span class="comment">//sensor measurement on white ground</span>
<a name="l00161"></a>00161   <a class="code" href="class_line_follow.html#a6f7f1f6ff879d0ce76823b03844bfc9a" title="Holds the minimum value that was measured during the calibration for &quot;white&quot;.">_calibrationSensorWhiteMin</a> = 1023;
<a name="l00162"></a>00162   <a class="code" href="class_line_follow.html#a7b4f3695a0133e9ba170199ddb1bdde6" title="Holds the maximum value that was measured during the calibration for &quot;white&quot;.">_calibrationSensorWhiteMax</a> = 0;
<a name="l00163"></a>00163   <span class="keywordflow">for</span>(byte i = 0; i &lt; 50; i++){
<a name="l00164"></a>00164     sensorValue = analogRead(<a class="code" href="class_line_follow.html#a0112816d723edd82daf2dabbf1ff074f" title="The reference to the configuration class.">_conf</a>-&gt;<a class="code" href="class_configuration.html#a683b496d15eca4addb13325d9707abcf">lineFollowLeftFrontSensorPin</a>);
<a name="l00165"></a>00165     <span class="keywordflow">if</span>(sensorValue &lt; <a class="code" href="class_line_follow.html#a6f7f1f6ff879d0ce76823b03844bfc9a" title="Holds the minimum value that was measured during the calibration for &quot;white&quot;.">_calibrationSensorWhiteMin</a>){
<a name="l00166"></a>00166       <a class="code" href="class_line_follow.html#a6f7f1f6ff879d0ce76823b03844bfc9a" title="Holds the minimum value that was measured during the calibration for &quot;white&quot;.">_calibrationSensorWhiteMin</a> = sensorValue;
<a name="l00167"></a>00167     }
<a name="l00168"></a>00168     <span class="keywordflow">if</span>(sensorValue &gt; <a class="code" href="class_line_follow.html#a7b4f3695a0133e9ba170199ddb1bdde6" title="Holds the maximum value that was measured during the calibration for &quot;white&quot;.">_calibrationSensorWhiteMax</a>){
<a name="l00169"></a>00169       <a class="code" href="class_line_follow.html#a7b4f3695a0133e9ba170199ddb1bdde6" title="Holds the maximum value that was measured during the calibration for &quot;white&quot;.">_calibrationSensorWhiteMax</a> = sensorValue;
<a name="l00170"></a>00170     }
<a name="l00171"></a>00171     delay(100);
<a name="l00172"></a>00172   }
<a name="l00173"></a>00173 
<a name="l00174"></a>00174   <span class="comment">//calculate the white threshold value</span>
<a name="l00175"></a>00175   <span class="keywordtype">int</span> rangeWhiteMaxToBlackMin = <a class="code" href="class_line_follow.html#aeb722614b85d484aafe0714f9d319f3e" title="Holds the minimum value that was measured during the calibration for &quot;black&quot;.">_calibrationSensorBlackMin</a> - <a class="code" href="class_line_follow.html#a7b4f3695a0133e9ba170199ddb1bdde6" title="Holds the maximum value that was measured during the calibration for &quot;white&quot;.">_calibrationSensorWhiteMax</a>;
<a name="l00176"></a>00176   <span class="comment">//calculate 1/3 out of the range and add it to the whiteMax. This will be the new whiteThreshold value.</span>
<a name="l00177"></a>00177   <span class="comment">//(We know that the calculation doesn&#39;t use float even though a division is made here.)</span>
<a name="l00178"></a>00178   <span class="keywordtype">int</span> oneThirdOfRange = rangeWhiteMaxToBlackMin/3;
<a name="l00179"></a>00179   <a class="code" href="class_line_follow.html#a0112816d723edd82daf2dabbf1ff074f" title="The reference to the configuration class.">_conf</a>-&gt;<a class="code" href="class_configuration.html#a6c0d6f8b78ea6b6e167c80bce9447906" title="Threshold value from black to white.">lineFollowWhiteThreshold</a> = _calibrationSensorWhiteMax + oneThirdOfRange;
<a name="l00180"></a>00180 
<a name="l00181"></a>00181   <span class="keywordtype">int</span> measurements[] = {
<a name="l00182"></a>00182     <a class="code" href="class_line_follow.html#aeb722614b85d484aafe0714f9d319f3e" title="Holds the minimum value that was measured during the calibration for &quot;black&quot;.">_calibrationSensorBlackMin</a>, <a class="code" href="class_line_follow.html#aaeea70b897deb0295401aa316189c2ba" title="Holds the maximum value that was measured during the calibration for &quot;black&quot;.">_calibrationSensorBlackMax</a>, <a class="code" href="class_line_follow.html#a6f7f1f6ff879d0ce76823b03844bfc9a" title="Holds the minimum value that was measured during the calibration for &quot;white&quot;.">_calibrationSensorWhiteMin</a>, <a class="code" href="class_line_follow.html#a7b4f3695a0133e9ba170199ddb1bdde6" title="Holds the maximum value that was measured during the calibration for &quot;white&quot;.">_calibrationSensorWhiteMax</a>,
<a name="l00183"></a>00183     oneThirdOfRange, <a class="code" href="class_line_follow.html#a0112816d723edd82daf2dabbf1ff074f" title="The reference to the configuration class.">_conf</a>-&gt;<a class="code" href="class_configuration.html#a6c0d6f8b78ea6b6e167c80bce9447906" title="Threshold value from black to white.">lineFollowWhiteThreshold</a>
<a name="l00184"></a>00184   };
<a name="l00185"></a>00185 
<a name="l00186"></a>00186   <a class="code" href="class_line_follow.html#a8c494126e578f00240532b866b051718" title="The reference to the serial communication class.">_com</a>-&gt;<a class="code" href="class_communication.html#a8679b3cb7ceef5527faa24454ce0f18a">send</a>(203, measurements, 6);
<a name="l00187"></a>00187 }
</pre></div></div><!-- contents -->
</div>
  <div id="nav-path" class="navpath">
    <ul>
      <li class="navelem"><a class="el" href="_line_follow_8cpp.html">LineFollow.cpp</a>      </li>

    <li class="footer">Generated on Fri May 4 2012 09:56:53 for prencar by
    <a href="http://www.doxygen.org/index.html">
    <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.8.0 </li>
   </ul>
 </div>


</body>
</html>
